﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_DAL;
using Zor_Modes;
using Zor_Tools;
namespace Zor_Bll
{
    /// <summary>
    /// 完税证领用
    /// </summary>
    /// create by liuqi at  2017.3.29 
    public class Zor_Certificate_Bll<T> where T : class
    {
        /// <summary>
        /// 获取完税证领用列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(int index, out int TotalCount,string where)
        {
            return PagerHelp<T>.GetPagerList(index, "dbo.V_Zor_Certificate", "Certificate_CreateTime desc", out TotalCount, where);
        }

        /// <summary>
        /// 修改完税证领用信息
        /// create zhl by 2017.4.10 修改加判断状态为未启用时才可以修改,当前完税证号初始默认起始号
        /// </summary>
        /// <param name="certificate">完税证领用对象</param>
        /// <returns></returns>
        public static BaseAnswer AlterCertificate(Zor_Certificate certificate)
        {
            certificate.Certificate_ModifyName = RequestSession.GetSessionUser().User_Id;
            certificate.Certificate_ModifyTime = TimeHelper.ToNowTimeStamp();
            certificate.Certificate_NowTaxNum = certificate.Certificate_StartTaxNum;
            certificate.Certificate_Balance = (int.Parse(certificate.Certificate_EndTaxNum) - int.Parse(certificate.Certificate_StartTaxNum));
            BaseAnswer bar = Zor_Certificate_DAL<T>.AlterCertificate(certificate);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "修改成功！" : "修改失败,请检查完税证号是否超出范围！";
            return bar;
        }

        /// <summary>
        /// 完税证领用-新增
        /// </summary>
        /// <param name="lease">租赁对象</param>
        /// <returns>执行结果</returns>
        public static BaseAnswer InsertCertificate(Zor_Certificate certificate)
        {
            certificate.User_Id = RequestSession.GetSessionUser().User_Id;
            certificate.Certificate_CreateTime = TimeHelper.ToNowTimeStamp().ToString();
            certificate.Certificate_NowTaxNum = certificate.Certificate_StartTaxNum;
            certificate.Certificate_Balance = (int.Parse(certificate.Certificate_EndTaxNum) - int.Parse(certificate.Certificate_StartTaxNum) + 1);
            BaseAnswer bar = Zor_Certificate_DAL<T>.InsertCertificate(certificate);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "增加成功！" : "新增失败，请检查字轨是否重复！";
            return bar;
        }

        /// <summary>
        /// 完税证领用-删除
        /// </summary>
        /// <param name="id">完税证领用信息ID集合</param>
        /// <returns></returns>
        public static BaseAnswer DeleteCertificate(int[] id)
        {
            BaseAnswer bar = Zor_Certificate_DAL<T>.DeleteCertificate(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "删除成功！" : "删除失败，请检查删除信息中是否存在已启用信息！";
            return bar;
        }

        /// <summary>
        /// 停用完税证领用信息-(未启用:0,已启用:1,已停用:2,已用完:3)
        /// create liuqi by 2017.3.29
        /// </summary>
        /// <param name="id">停用的Id</param>
        /// <returns></returns>
        public static BaseAnswer StopCertificate(int[] id)
        {
            BaseAnswer bar = Zor_Certificate_DAL<T>.StopCertificate(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "停用成功！" : "停用失败，请检查信息是否为已启用！";
            return bar;
        }

        /// <summary>
        /// 查询所有街道办
        /// </summary>
        /// <returns></returns>
        public static List<T> GetStreetOffice()
        {
            return Zor_Certificate_DAL<T>.GetStreetOffice();
        }
    }
}
